import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;

import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialException;

import codeTools.MyEncoder;
import dbcTools.DBC_MySQL;
import model.Chat_Group;
import model.Chat_Group_member;
import model.GroupMessageDBTO;
import model.Group_Dao;
import model.Group_member_Dao;
import model.UserDBTO;

/**
 * 本类是为了向MyWeChat添加数据
 */
public class InitDBTD {
	public static void main(String[] args) throws SerialException, SQLException, IOException {
		DBC_MySQL dbc_MySQL = new DBC_MySQL("config.xml");
		Connection connection = dbc_MySQL.getConnection();
		connection.setAutoCommit(false);

//		InitDBTD.insertUser(connection);
		InitDBTD.insertGroupMessage(connection);

		connection.commit();
		
		
		//lq:
//		InitDBTD.insertGroup();
//		InitDBTD.insertGroupMember();
		
		
	}
	public static void insertGroupMember() {
		Group_member_Dao group_member_Dao = new Group_member_Dao();
		group_member_Dao.addOne(5, 27, "群主", "小红", "group1", 0);
		group_member_Dao.addOne(5, 28, "群主", "小橙", "group1", 0);
		
		group_member_Dao.addOne(6, 27, "群主", "小红", "group2", 0);
		group_member_Dao.addOne(6, 29, "成员", "小黄", "group2", 0);
		
		group_member_Dao.addOne(7, 27, "群主", "小红", "group3", 0);
		group_member_Dao.addOne(7, 28, "管理员", "小橙", "group3", 0);
		group_member_Dao.addOne(7, 30, "成员", "小绿", "group3", 0);
	}
	
	public static void insertGroup() throws SerialException, IOException, SQLException {
		Group_Dao group_Dao = new Group_Dao();
		group_Dao.addGroup("group1", "png", MyEncoder.pictureToBlob("group_avatar_png/群1.png"), 50, "好友组", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group2", "png", MyEncoder.pictureToBlob("group_avatar_png/群2.png"), 50, "讨论组", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group3", "png", MyEncoder.pictureToBlob("group_avatar_png/群3.png"), 50, "普通群", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group4", "png", MyEncoder.pictureToBlob("group_avatar_png/群4.png"), 50, "普通群", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group5", "png", MyEncoder.pictureToBlob("group_avatar_png/群5.png"), 50, "普通群", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group6", "png", MyEncoder.pictureToBlob("group_avatar_png/群6.png"), 50, "普通群", new Timestamp(System.currentTimeMillis()));
		group_Dao.addGroup("group7", "png", MyEncoder.pictureToBlob("group_avatar_png/群7.png"), 50, "普通群", new Timestamp(System.currentTimeMillis()));
	}
	
	public static void insertGroupMessage(Connection connection) throws SQLException {
		GroupMessageDBTO groupMessageDBTO = new GroupMessageDBTO(connection);
//		groupMessageDBTO.addNewGroupMessage(group_id, user_id, content_type, content)
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(5, 27, "String", "你好，hello。")
			);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(5, 28, "String", "你好，hello。")
			);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(5, 27, "String", "我喜欢蛋糕，你呢？")
			);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(5, 28, "String", "真巧，我也是，尤其是奶油多的我最喜欢了。")
			);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(6, 27, "String", "你好，hello。")
		);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(6, 29, "String", "你好，hello。")
		);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(6, 27, "String", "记得明天下午三点等我哦！")
		);
		System.out.println(
				groupMessageDBTO.addNewGroupMessage(6, 29, "String", "恩，不见不散！")
		);
	}
	public static void insertUser(Connection connection) throws SerialException, SQLException, IOException {
		UserDBTO userDBTO = new UserDBTO(connection);
		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户1.png"), "小红", "北京", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户2.png"), "小橙", "上海", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户3.png"), "小黄", "广州", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户4.png"), "小绿", "深圳", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户5.png"), "小蓝", "宜春", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户6.png"), "小靛", "河南", "123456", "123456")
			);

		System.out.println(
				userDBTO.addNewUser("png", MyEncoder.pictureToBlob("user_avatar_png/用户7.png"), "小紫", "台湾", "123456", "123456")
			);
	}
}
